//
//  StatusTopView.swift
//  我的微博练习
//
//  Created by zhangguo on 15/10/14.
//  Copyright © 2015年 zhangguo. All rights reserved.
//

import UIKit
import SDWebImage

class StatusTopView: UIView {

    //微博模型数据设置
    var status:Status?{
        didSet{
        
            if let url = status?.user?.imageURL{
                   iconView.sd_setImageWithURL(url)
            }
         vipIconView.image = status?.user?.vipImage
         memberIconView.image = status?.user?.memberImage
         nameLabel.text = status?.user?.name ?? ""
      
        timeLabel.text = NSDate.sinaDate(status?.created_at ?? "")? .dateDesctiption
         sourceLabel.text = status?.source
         
        }
}
  
    //搭建界面
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.clearColor()
           setUpUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //添加控件
    private func setUpUI() {
        
        //添加顶部分割视图
        let sepView = UIView()
        sepView.backgroundColor = UIColor(white: 0.9, alpha: 1)
        addSubview(sepView)
        sepView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 10))
        
        //添加子控件
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(memberIconView)
        addSubview(vipIconView)
     
        //自动布局
        iconView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: sepView, size: CGSize(width: 35, height: 35), offset: CGPoint(x: statusCellControlMargin, y: statusCellControlMargin))

        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: statusCellControlMargin, y: 0))
        timeLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: statusCellControlMargin, y: 0))
        sourceLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: timeLabel, size: nil, offset: CGPoint(x: statusCellControlMargin, y: 0))
        memberIconView.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: nameLabel, size: nil, offset: CGPoint(x: statusCellControlMargin, y: 0))
        
        //底部约束
        vipIconView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: statusCellControlMargin, y: statusCellControlMargin))
    }

    //懒加载控件
    //头像
     private lazy var iconView:UIImageView = UIImageView()
     private lazy var nameLabel:UILabel = UILabel(Color: UIColor.darkGrayColor(), fontSize: 14)
     private lazy var timeLabel:UILabel = UILabel(Color: UIColor.orangeColor(), fontSize: 9)
    //来源标签
     private lazy var sourceLabel:UILabel = UILabel(Color: UIColor.lightGrayColor(), fontSize: 9)
//    会员图标
     private lazy var memberIconView:UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_level1"))
    //vip标志
    private lazy var vipIconView:UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))

}
